<script>
	import {
		getToken,
		setToken
	} from '@/utils/auth'
	import request from "./utils/request.js"
	import footerBar from "pages/common/footer-bar"
	export default {
		components: {
			footerBar
		},
		onLaunch: function() {
			console.log('App Launch');
		},
		onShow:async function() {
			var token = getToken();
			if (!token) {
				uni.reLaunch({
					url: './pages/login/login'
				})
			}
			// token 存在检测token是否有效
			if (token) {
				await this.checkToken();
				var a = this.userInfo
			}
		},
		data() {
			return {
				userInfo: null
			}
		},
		methods: {
			checkToken: async function(){
				return new Promise((resolve, reject) => {
				    request({
				    	url: '/system/user/info',
				    	method: 'post',
				    }).then(response => {
				    	this.userInfo = response;
						resolve(response);
				    })
				 })
			}
			
		},
		onHide: function() {
			
		}
	}
</script>

<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "uview-ui/index.scss";
</style>
